//
//  LCLeftViewController.m
//  YinYueTai
//
//  Created by CongCong on 15-7-18.
//  Copyright (c) 2015年 CongCong. All rights reserved.
//

#import "LCLeftViewController.h"

@interface LCLeftViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic) BOOL isPlay;
@property (nonatomic) NSArray *dataArray;
@end

@implementation LCLeftViewController
+ (id)shareLeft
{
    static id shareObject = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        shareObject = [[self alloc]init];
        
    });
    return shareObject;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
    self.dataArray = @[@"电台",@"阅读",@"帖子",@"随笔",@"设置"];
    self.isPlay = YES;
}
- (void)initUI
{
    self.view.backgroundColor = [UIColor redColor];
    self.tabView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    _tabView.delegate = self;
    _tabView.dataSource = self;
    [self.view addSubview:_tabView];
    [_tabView registerNib:[UINib nibWithNibName:@"LCLeftCell" bundle:nil] forCellReuseIdentifier:@"LCLeftCell"];
    
}

#pragma mark---> tabView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([AFSoundManager sharedManager].isPlaying) {
        return self.dataArray.count+1;
    }
    return self.dataArray.count;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==5) {
        LCLeftCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LCLeftCell" forIndexPath:indexPath];
       
        LCRdListenViewController *manger = [LCRdListenViewController shareListen];
        if (manger.musicArray.count==0) {
            return cell;
        }
        NSInteger i = manger.index;
        LCRdDetailListModel *model =  manger.musicArray[i];
        [cell showModel:model withPlay:self.isPlay];
        return cell;
        
    }
    else
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cellID"];
        }
        cell.textLabel.text = self.dataArray[indexPath.row];
        return cell;
    }
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    return 100;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.row==5) {
        
        return 100;
    }
    else
    {
        return (kScreenSize.height-200)/6;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
        {
            LCRadioViewController *radio = [[LCRadioViewController alloc]init];
            radio.title = @"电台";
            UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:radio];
            [self.mm_drawerController setCenterViewController:nav withCloseAnimation:YES completion:nil];
        }
            break;
        case 1:
        {
            LCReadViewController *read = [[LCReadViewController alloc]init];
            read.title = @"阅读";
            UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:read];
            [self.mm_drawerController setCenterViewController:nav withCloseAnimation:YES completion:nil];
        }
            break;
        case 2:
        {
            LCGroupNewViewController *group = [[LCGroupNewViewController alloc]init];
            group.title = @"帖子";
            UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:group];
            [self.mm_drawerController setCenterViewController:nav withCloseAnimation:YES completion:nil];
        }
            break;
        case 3:
        {
            LCTimeLineViewController *timeLine = [[LCTimeLineViewController alloc]init];
            timeLine.title = @"随笔";
            UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:timeLine];
            [self.mm_drawerController setCenterViewController:nav withCloseAnimation:YES completion:nil];
        }
            break;
        case 4:
        {
            LCSettiongViewController *setting = [[LCSettiongViewController alloc]init];
            setting.title = @"设置";
            UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:setting];
            [self.mm_drawerController setCenterViewController:nav withCloseAnimation:YES completion:nil];
        }
            break;
        case 5:
        {
            
            LCRdListenViewController *listen = [LCRdListenViewController shareListen];
            UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:listen];
            
            [self.mm_drawerController setCenterViewController:nav withCloseAnimation:YES completion:nil];
            
        }
            break;
            
        default:
            break;
    }
}

//- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
//{
//    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100)];
//    AFSoundManager *manger = [AFSoundManager sharedManager];
//    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
//    [imageView sd_setImageWithURL:[NSURL URLWithString:[[manger.musicArray objectAtIndex:manger.page] coverimg]] placeholderImage:[UIImage imageNamed:@"hoder"]];
//    [view addSubview:imageView];
//    return view;
//}
//
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 1;
}
@end
